<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" xmlns:oso="http://osoftware.com/facelets" template="/WEB-INF/templates/mainEditLayout.xhtml">

	<ui:define name="title">
			#{resourceBundle['patientEvaluation.title']}
	</ui:define>

	<ui:define name="editFields">
		<p:accordionPanel id="acc">
			<p:tab title="Principal">
				<h:panelGrid columns="3">
					<oso:selectOneMenu id="specialist" label="#{resourceBundle['patientEvaluation.specialist']}" value="#{patientEvaluationModel.specialist}" converter="specialistConverter"
						items="#{patientEvaluationModel.selectableSpecialists}" itemLabel="fullName" required="true" />
					<oso:selectOneMenu id="patientFilter" label="#{resourceBundle['patientEvaluation.patient']}" value="#{patientEvaluationModel.patient}" converter="patientConverter"
						items="#{patientEvaluationModel.selectablePatients}" itemLabel="fullName" />

					<oso:calendar id="from" label="#{resourceBundle['patientEvaluation.from']}" value="#{patientEvaluationModel.from}" required="true" />

					<oso:calendar id="to" label="#{resourceBundle['patientEvaluation.to']}" value="#{patientEvaluationModel.to}" required="true" />

					<oso:textEditor id="evaluation" label="#{resourceBundle['patientEvaluation.evaluation']}" value="#{patientEvaluationModel.evaluation}" required="true" />
				</h:panelGrid>
			</p:tab>
			<p:tab title="Comentarios">
				<h:panelGrid columns="3">
					<p:commandButton id="addObservation" value="Nuevo" oncomplete="observationdialog.show();" process="@this" actionListener="#{patientEvaluationController.addObservationEvent}"
						update=":observationdialogForm:observationdialogVar">
					</p:commandButton>
					<p:dataTable id="listTable" var="row" value="#{patientEvaluationModel.editedEntity.observations}" paginator="true"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,15"
						emptyMessage="#{resourceBundle['list.noData']}" paginatorAlwaysVisible="false">
						<p:column sortBy="#{row.date}">
							<f:facet name="header">
								<h:outputText value="#{resourceBundle['observation.date']}" />
							</f:facet>
							<h:outputText value="#{row.date}" />
						</p:column>
						<p:column sortBy="#{row.author}">
							<f:facet name="header">
								<h:outputText value="#{resourceBundle['observation.author']}" />
							</f:facet>
							<h:outputText value="#{row.author}" />
						</p:column>
						<p:column sortBy="#{row.observation}">
							<f:facet name="header">
								<h:outputText value="#{resourceBundle['observation.observation']}" />
							</f:facet>
							<h:outputText value="#{row.observation}" />
						</p:column>
					</p:dataTable>
				</h:panelGrid>
			</p:tab>
		</p:accordionPanel>
		<h:outputText value="" />
		<h:outputText value="" />

	</ui:define>

	<ui:define name="afterForm">
		<h:form id="observationdialogForm">
			<p:dialog widgetVar="observationdialog" header="Observaciones" showEffect="clip" hideEffect="clip" id="observationdialogVar">
				<p:panelGrid columns="3">
					<h:outputText id="date" label="#{resourceBundle['observation.date']}" value="#{patientEvaluationModel.editedObservation.date}" />


					<oso:inputText id="observation" label="#{resourceBundle['observation.observation']}" value="#{patientEvaluationModel.editedObservation.observation}" required="true" />


					<p:commandButton id="submitObservationButton" value="#{resourceBundle['btn.save']}" action="observationEvent" update=":editForm:acc:listTable" process="observationdialogVar" execute="@this"
						oncomplete="handleObservationServerResponse(xhr, status, args)" />
					<p:commandButton value="#{resourceBundle['btn.cancel']}" oncomplete="handleObservationServerResponse(xhr, status, args)" process="@none" />
				</p:panelGrid>
			</p:dialog>
		</h:form>
		<script type="text/javascript">
	        function handleObservationServerResponse(xhr, status, args) {
	            if (!args.validationFailed) {
	            	observationdialog.hide();
	            }
	        }
	    </script>
	</ui:define>

</ui:composition>